﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class Manage_Service_tlogin : System.Web.UI.Page
{
    string n = string.Empty;
    string p = string.Empty;
    protected void Page_Load(object sender, EventArgs e) {
        if (!string.IsNullOrEmpty(Request.Form["n"])) {
            n = Request.Form["n"];
        }
        if (!string.IsNullOrEmpty(Request.Form["p"])) {
            p = Request.Form["p"];
        }
        if (n == "") {
            Response.Write("e3"); Response.End();
        }
        if (p == "") {
            Response.Write("e1"); Response.End();
        }

        string result = "";

        Exam.Core.Model.Master model = new Exam.Core.DAL.Master().getMasterByName(Server.HtmlEncode(n));

        if (model.MasterPassword == "") {//用户不存在
            result = "e0";
        }
        else {
            if (model.MasterPassword.ToLower().Trim() == p.ToLower().Trim()) {//密码正确
                StringBuilder sb = new StringBuilder();
                sb.Append(model.MasterID.Trim());
                sb.Append("|");
                sb.Append(Server.UrlEncode(model.MasterName.Trim()));
                sb.Append("|");
                sb.Append(model.MasterPassword.Trim());
                sb.Append("|");
                sb.Append(model.DepartmentID.Trim());
                sb.Append("|");
                sb.Append(model.CourseId.Trim());
                Cookie.SaveCookie(ExamSys.teacher_cookiesname.Trim(), sb.ToString(), 720);
                result = "ok";
            }
            else {//密码错误
                result = "e1";
            }
        }

        Response.Write(result);
        Response.End();

    }
}